package com.explore.demo.controller;


import com.explore.demo.common.ServerResponse;
import com.explore.demo.pojo.Category;
import com.explore.demo.service.CategoryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gaolainan
 * @since 2021-04-14
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @GetMapping
    @ApiOperation("查询全部的类别")
    public ServerResponse query(){
        return categoryService.queryAll();
    }

    @PostMapping
    @ApiOperation("创建一个类别")
    public ServerResponse addOne(Category category){
        return categoryService.addCategory(category);
    }

    @DeleteMapping
    @ApiOperation("根据类别名称 删除类别")
    public ServerResponse deleteByName(String categoryName){
        return categoryService.deleteCategoryByCategoryName(categoryName);
    }

    @PostMapping("/{categoryName}")
    @ApiOperation("通过类别名称 查询类别的相关信息")
    public ServerResponse queryByName(@PathVariable("categoryName") String categoryName){
        return categoryService.queryCategoryByCategoryName(categoryName);
    }

    @PutMapping
    @ApiOperation("更新类别的信息")
    public ServerResponse updateCategory(@RequestBody Category category){
        return categoryService.updateCategory(category);
    }
}

